home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / twm / part01 next >
Encoding:
Internet Message Format  |  1988-06-12  |  59.4 KB

  1. Subject:  v15i064:  A window manager for X, Part01/04
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Tom LaStrange <esunix!tlastran>
  7. Posting-number: Volume 15, Issue 64
  8. Archive-name: twm/part01
  9.  
  10.  
  11. Here is my first source posting to comp.unix.sources.  I hope this is the
  12. appropriate place for this code.  There are 3 shar files for "twm".  Twm
  13. is a window manager for X11.
  14.  
  15. Twm has never been compiled or run on a System V machine.  All development
  16. was done on a Sun 3 running Release 3.4 of the operating system.  It has
  17. also been run on a VaxStation II and a VaxStation 8000.
  18.  
  19. Nothing real special you should have to do to compile it.  If you are
  20. running X11R1, you will have to link in the resource manager library in
  21. addition to libX11.a.
  22.  
  23. We here at E&S have been using twm for almost 6 months now in various
  24. states of development.  I hope you find it to be useful tool.  Twm is my
  25. first, and so far, only X program.  If I'm doing anything blatently wrong,
  26. forgive me.
  27.  
  28. I would appreciate hearing from those who like it as well as those who
  29. dislike it.
  30.  
  31. --
  32. Tom LaStrange
  33. Evans & Sutherland Computer Corporation
  34.  
  35. UUCP Address:  {ihnp4,seismo}!utah-cs!utah-gr!uplherc!esunix!tlastran
  36. Alternate:     {ihnp4,decvax}!decwrl!esunix!tlastran
  37.  
  38. -------------------------------------------
  39. #! /bin/sh
  40. # This is a shell archive, meaning:
  41. # 1.  Remove everything above the #! /bin/sh line.
  42. # 2.  Save the resulting test in a file
  43. # 3.  Execute the file with /bin/sh (not csh) to create the files:
  44. #
  45. #Makefile
  46. #README
  47. #Sample.twmrc
  48. #gram.y
  49. #lex.l
  50. #add_window.c
  51. #gc.c
  52. #list.c
  53. #twm.c
  54. #parse.c
  55. #
  56. # Created by tlastran (Tom LaStrange) on Fri Apr 15 07:22:56 MDT 1988
  57. #
  58. if test -f 'Makefile'
  59. then
  60.     echo shar: will not over-write existing file "Makefile"
  61. else
  62. echo extracting "Makefile"
  63. sed 's/^X//' >Makefile <<'SHAR_EOF'
  64. X#**********************************************************************
  65. X#
  66. X#  twm Makefile
  67. X#
  68. X#**********************************************************************
  69. X
  70. X.SUFFIXES: .y .o
  71. X
  72. X.y.o:
  73. X    yacc -d $*.y
  74. X    mv y.tab.c $*.c
  75. X    mv y.tab.h $*.h
  76. X    $(CC) -c $(CFLAGS) $*.c
  77. X
  78. X#
  79. X#  If you are running X11R1, then you must use the resource manager
  80. X#  library in addition to libX11.a
  81. X#
  82. X#LIBS= -lX11 -lXrm
  83. XLIBS= -lX11
  84. X
  85. XCFLAGS= -O
  86. XLDFLAGS=
  87. X
  88. XO_FILES=\
  89. X        gram.o\
  90. X        lex.o\
  91. X        add_window.o\
  92. X        gc.o\
  93. X        list.o\
  94. X        twm.o\
  95. X        parse.o\
  96. X        menus.o\
  97. X        events.o\
  98. X        resize.o\
  99. X        util.o\
  100. X        version.o
  101. X
  102. X
  103. Xtwm:    $(O_FILES)
  104. X    cc $(LDFLAGS) -o twm $(O_FILES) $(LIBS)
  105. X
  106. X#
  107. X#  Dependencies
  108. X#
  109. Xgram.o: \
  110. X    twm.h \
  111. X    menus.h \
  112. X    list.h
  113. Xlex.o: \
  114. X    gram.h
  115. Xutil.o: \
  116. X    twm.h \
  117. X    gram.h
  118. Xresize.o: \
  119. X    twm.h \
  120. X    util.h \
  121. X    resize.h \
  122. X    resize.bm \
  123. X    focus.bm
  124. Xevents.o: \
  125. X    twm.h \
  126. X    add_window.h \
  127. X    menus.h \
  128. X    events.h \
  129. X    resize.h \
  130. X    gram.h \
  131. X    twm.bm
  132. Xmenus.o: \
  133. X    twm.h \
  134. X    gc.h \
  135. X    menus.h \
  136. X    events.h \
  137. X    util.h \
  138. X    gram.h \
  139. X    pull.bm
  140. Xparse.o: \
  141. X    twm.h \
  142. X    menus.h \
  143. X    util.h
  144. Xtwm.o: \
  145. X    twm.h \
  146. X    add_window.h \
  147. X    gc.h \
  148. X    parse.h \
  149. X    version.h \
  150. X    menus.h \
  151. X    events.h \
  152. X    util.h \
  153. X    twm.bm
  154. Xlist.o: \
  155. X    twm.h \
  156. X    gram.h
  157. Xgc.o: \
  158. X    twm.h
  159. Xadd_window.o: \
  160. X    twm.h \
  161. X    util.h \
  162. X    resize.h \
  163. X    gram.h \
  164. X    list.h \
  165. X    iconify.bm \
  166. X    resize.bm \
  167. X    xterm.bm \
  168. X    focus.bm \
  169. X    hilite.bm
  170. Xlex.o: \
  171. X    gram.h
  172. Xgram.o: \
  173. X    twm.h \
  174. X    menus.h \
  175. X    list.h
  176. SHAR_EOF
  177. if test 1405 -ne "`wc -c < Makefile`"
  178. then
  179.     echo shar: error transmitting "Makefile" '(should have been 1405 characters)'
  180. fi
  181. fi
  182. if test -f 'README'
  183. then
  184.     echo shar: will not over-write existing file "README"
  185. else
  186. echo extracting "README"
  187. sed 's/^X//' >README <<'SHAR_EOF'
  188. XApril 15, 1988
  189. X
  190. XHere you go, here are some things I can think of.
  191. X
  192. XTwm has never been compiled or run on a System V machine.  All
  193. Xdevelopment was done on a Sun 3 running Release 3.4 of the operating system. 
  194. XIt has also been run on a VaxStation II and a VaxStation 8000.  
  195. X
  196. XNothing real special you should have to do to compile it.  If you are
  197. Xrunning X11R1, you will have to link in the resource manager library
  198. Xin addition to libX11.a.
  199. X
  200. XWe here at E&S have been using twm for almost 6 months now in various
  201. Xstates of development.  I hope you find it to be useful tool.
  202. XTwm is my first, and so far, only X program.  If I'm doing anything
  203. Xblatently wrong, forgive me.
  204. X
  205. XI would appreciate hearing from those who like it as well as those who
  206. Xdislike it.
  207. X
  208. X--
  209. XTom LaStrange
  210. X"if you don't like it, don't use it"
  211. X
  212. XEvans & Sutherland Computer Corporation
  213. X
  214. XUUCP Address:  {ihnp4,seismo}!utah-cs!utah-gr!uplherc!esunix!tlastran
  215. XAlternate:     {ihnp4,decvax}!decwrl!esunix!tlastran
  216. SHAR_EOF
  217. if test 972 -ne "`wc -c < README`"
  218. then
  219.     echo shar: error transmitting "README" '(should have been 972 characters)'
  220. fi
  221. fi
  222. if test -f 'Sample.twmrc'
  223. then
  224.     echo shar: will not over-write existing file "Sample.twmrc"
  225. else
  226. echo extracting "Sample.twmrc"
  227. sed 's/^X//' >Sample.twmrc <<'SHAR_EOF'
  228. X#**********************************************************************
  229. X#
  230. X#    .twmrc
  231. X#
  232. X#**********************************************************************
  233. X
  234. X# ReverseVideo
  235. XWarpCursor
  236. XUnknownIcon    "/usr/ias_soft/tlastrange/.icon"
  237. XBorderWidth    2
  238. XTitleFont    "8x13"
  239. XMenuFont    "8x13"
  240. XIconFont    "8x13"
  241. XResizeFont    "fg-22"
  242. X
  243. XButton1        f.menu "button1"
  244. XButton2        f.menu "button2"
  245. XButton3        f.menu "button3"
  246. XButton4        f.nop
  247. XButton5        f.nop
  248. X
  249. XTitleButton1    t.raise
  250. XTitleButton2    t.move
  251. XTitleButton3    t.lower
  252. XTitleButton4    t.nop
  253. XTitleButton5    t.nop
  254. X
  255. XNoTitle
  256. X{
  257. X  "xclock"
  258. X  "xckmail"
  259. X}
  260. X
  261. XAutoRaise
  262. X{
  263. X  "xterm"    # auto-raise all my xterm windows
  264. X}
  265. X
  266. Xmenu "button1"
  267. X{
  268. X"Other Logins"    f.title
  269. X"iguana 24"    !"xterm -T xterm_iguana_24 =80x24+100+100 -e rlogin iguana &"
  270. X"iguana 48"    !"xterm -T xterm_iguana_48 =80x48+50+50 -e rlogin iguana &"
  271. X"worm 24"    !"xterm -T xterm_worm_24 =80x24+100+100 &"
  272. X"worm 48"    !"xterm -T xterm_worm_48 =80x48+50+50 &"
  273. X"shiva"        !"xterm -T xterm_shiva =80x24+200+200 -e rlogin shiva &"
  274. X"tegus"        !"xterm -T xterm_tegus =80x24+200+200 -e rlogin tegus &"
  275. X"shade"        !"xterm -T xterm_shade =80x24+200+200 -e rlogin shade &"
  276. X"bilbo"        !"xterm -T xterm_bilbo =80x24+250+250 -e rlogin bilbo &"
  277. X"frodo"        !"xterm -T xterm_frodo =80x24+300+300 -e rlogin frodo &"
  278. X"esunix"    !"xterm -T xterm_esunix =80x24+350+350 -e rlogin esunix &"
  279. X"lynx8"        !"xterm -T xterm_lynx8 =80x24+370+370 -e rlogin lynx8 &"
  280. X"lynx13"    !"xterm -T xterm_lynx13 =80x24+390+390 -e rlogin lynx13 &"
  281. X"zephyr"    !"xterm -T xterm_zephyr =80x24+390+390 -e rlogin zephyr &"
  282. X}
  283. X
  284. Xmenu "button2"
  285. X{
  286. X"Window Ops"        f.title
  287. X"Refresh"        f.refresh
  288. X"Focus on Root"        f.focus
  289. X"Source .twmrc"        f.twmrc
  290. X"Source blob"        f.source "blob"
  291. X"Cut File"        f.cutfile
  292. X"twm Version"        f.version
  293. X"Kill twm"        f.quit
  294. X}
  295. X
  296. Xmenu "button3"
  297. X{
  298. X"Cut Buffer"        f.title
  299. X"Procedure Header"    f.file "/usr/ias_soft/tlastrange/src/proc.twm"
  300. X"File Header"        f.file "/usr/ias_soft/tlastrange/src/file.twm"
  301. X"pull right"        f.menu "blob"
  302. X}
  303. X
  304. Xmenu "blob"
  305. X{
  306. X"pull right"        f.menu "final"
  307. X"another"        ^"some text"
  308. X}
  309. X
  310. Xmenu "final"
  311. X{
  312. X"Cut Buffer"        f.title
  313. X"Procedure Header"    f.file "/usr/ias_soft/tlastrange/src/proc.twm"
  314. X"File Header"        f.file "/usr/ias_soft/tlastrange/src/file.twm"
  315. X}
  316. X
  317. Xmenu "one"
  318. X{
  319. X"refresh" f.refresh
  320. X}
  321. SHAR_EOF
  322. if test 2194 -ne "`wc -c < Sample.twmrc`"
  323. then
  324.     echo shar: error transmitting "Sample.twmrc" '(should have been 2194 characters)'
  325. fi
  326. fi
  327. if test -f 'gram.y'
  328. then
  329.     echo shar: will not over-write existing file "gram.y"
  330. else
  331. echo extracting "gram.y"
  332. sed 's/^X//' >gram.y <<'SHAR_EOF'
  333. X/*****************************************************************************/
  334. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  335. X/**                          Salt Lake City, Utah                           **/
  336. X/**                                                                         **/
  337. X/**                           All Rights Reserved                           **/
  338. X/**                                                                         **/
  339. X/**    Permission to use, copy, modify, and distribute this software and    **/
  340. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  341. X/**    granted, provided that the above copyright notice appear  in  all    **/
  342. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  343. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  344. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  345. X/**    city pertaining to distribution  of the software without  specif-    **/
  346. X/**    ic, written prior permission.                                        **/
  347. X/**                                                                         **/
  348. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  349. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  350. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  351. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  352. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  353. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  354. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  355. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  356. X/*****************************************************************************/
  357. X
  358. X/***********************************************************************
  359. X *
  360. X * $Header: gram.y,v 1.15 88/04/15 07:09:34 tlastran Exp $
  361. X *
  362. X * .twmrc command grammer
  363. X *
  364. X * 07-Jan-86 Thomas E. LaStrange    File created
  365. X *
  366. X ***********************************************************************/
  367. X
  368. X%{
  369. Xstatic char RCSinfo[]=
  370. X"$Header: gram.y,v 1.15 88/04/15 07:09:34 tlastran Exp $";
  371. X
  372. X#include <stdio.h>
  373. X#include "twm.h"
  374. X#include "menus.h"
  375. X#include "list.h"
  376. X
  377. Xstatic char *Action = "";
  378. Xstatic MenuRoot    *root,
  379. X        *pull = NULL;
  380. X
  381. XMenuRoot *GetRoot();
  382. X
  383. Xstatic char *ptr;
  384. Xstatic int Button;
  385. Xstatic int list;
  386. X
  387. Xextern int yylineno;
  388. X%}
  389. X
  390. X%union
  391. X{
  392. X    int num;
  393. X    char *ptr;
  394. X};
  395. X
  396. X%token <num> LB RB MENUS MENU BUTTON TBUTTON
  397. X%token <num> F_MENU F_FOCUS F_REFRESH F_FILE F_TWMRC F_CIRCLEUP F_QUIT
  398. X%token <num> F_NOP F_TITLE F_VERSION F_EXEC F_CUT F_CIRCLEDOWN F_SOURCE
  399. X%token <num> F_CUTFILE
  400. X%token <num> T_NOP T_RAISE T_LOWER T_MOVE
  401. X%token <num> WARPCURSOR NUMBER BORDERWIDTH TITLE_FONT REVERSE_VIDEO
  402. X%token <num> RESIZE_FONT NO_TITLE AUTO_RAISE
  403. X%token <num> MENU_FONT ICON_FONT UNKNOWN_ICON
  404. X%token <ptr> STRING
  405. X
  406. X%type <ptr> string
  407. X%type <num> action button number tbutton taction
  408. X
  409. X%start twmrc 
  410. X
  411. X%%
  412. Xtwmrc        : stmts
  413. X        ;
  414. X
  415. Xstmts        : /* Empty */
  416. X        | stmts stmt
  417. X        ;
  418. X
  419. Xstmt        : error
  420. X        | REVERSE_VIDEO        { if (FirstTime) ReverseVideo = TRUE; }
  421. X        | ICON_FONT string    { if (FirstTime) IconFontName = $2; }
  422. X        | RESIZE_FONT string    { if (FirstTime) SizeFontName = $2; }
  423. X        | MENU_FONT string    { if (FirstTime) MenuFontName = $2; }
  424. X        | TITLE_FONT string    { if (FirstTime) TitleBarFontName=$2; }
  425. X        | UNKNOWN_ICON string    { if (FirstTime) GetUnknownIcon($2); }
  426. X        | WARPCURSOR        { if (FirstTime) WarpCursor = TRUE; }
  427. X        | BORDERWIDTH number    { if (FirstTime) BorderWidth = $2; }
  428. X        | button string        { root = GetRoot($2);
  429. X                      Menu[$1] = root;
  430. X                      Item[$1] = NULL;
  431. X                    }
  432. X        | button action        { if ($2 == F_MENU)
  433. X                      {
  434. X                        pull->prev = NULL;
  435. X                        Menu[$1] = pull;
  436. X                        Item[$1] = NULL;
  437. X                      }
  438. X                      else
  439. X                      {
  440. X                        root = GetRoot(TWM_ROOT);
  441. X                           Item[$1] =
  442. X                        AddToMenu(root,"x",Action,0,$2);
  443. X                        Menu[$1] = NULL;
  444. X                      }
  445. X                      Action = "";
  446. X                      pull = NULL;
  447. X                    }
  448. X        | tbutton taction    { TitleButton[$1] = $2; }
  449. X        | NO_TITLE        { list = NO_TITLE; }
  450. X          win_list
  451. X        | AUTO_RAISE        { list = AUTO_RAISE; }
  452. X          win_list
  453. X        | MENU string        { root = GetRoot($2); }
  454. X          menu
  455. X        ;
  456. X
  457. X
  458. Xwin_list    : LB win_entries RB
  459. X        ;
  460. X
  461. Xwin_entries    : /* Empty */
  462. X        | win_entries win_entry
  463. X        ;
  464. X
  465. Xwin_entry    : string        { if (FirstTime) AddToList(list, $1); }
  466. X        ;
  467. X
  468. Xmenu        : LB menu_entries RB
  469. X        ;
  470. X
  471. Xmenu_entries    : /* Empty */
  472. X        | menu_entries menu_entry
  473. X        ;
  474. X
  475. Xmenu_entry    : string action        { AddToMenu(root, $1, Action, pull, $2);
  476. X                      Action = "";
  477. X                      pull = NULL;
  478. X                    }
  479. X        ;
  480. X
  481. Xaction        : F_NOP            { $$ = F_NOP; }
  482. X        | F_QUIT        { $$ = F_QUIT; }
  483. X        | F_FOCUS        { $$ = F_FOCUS; }
  484. X        | F_REFRESH        { $$ = F_REFRESH; }
  485. X        | F_SOURCE string    { Action = $2; $$ = F_TWMRC; }
  486. X        | F_TWMRC        { $$ = F_TWMRC; }
  487. X        | F_VERSION        { $$ = F_VERSION; }
  488. X        | F_TITLE        { $$ = F_TITLE; }
  489. X        | F_CIRCLEUP        { $$ = F_CIRCLEUP; }
  490. X        | F_CIRCLEDOWN        { $$ = F_CIRCLEDOWN; }
  491. X        | F_CUTFILE        { $$ = F_CUTFILE; }
  492. X        | F_MENU string        { pull = GetRoot($2);
  493. X                      pull->prev = root;
  494. X                      $$ = F_MENU;
  495. X                    }
  496. X        | F_FILE string        { Action = $2; $$ = F_FILE; }
  497. X        | F_EXEC string        { Action = $2; $$ = F_EXEC; }
  498. X        | F_CUT string        { Action = $2; $$ = F_CUT; }
  499. X        ;
  500. X
  501. Xtaction        : T_RAISE        { $$ = T_RAISE; }
  502. X        | T_LOWER        { $$ = T_LOWER; }
  503. X        | T_MOVE        { $$ = T_MOVE; }
  504. X        | T_NOP            { $$ = T_NOP; }
  505. X        ;
  506. X
  507. Xbutton        : BUTTON        { $$ = $1;
  508. X                      if ($1 == 0)
  509. X                        yyerror();
  510. X
  511. X                      if ($1 > MAX_BUTTONS)
  512. X                      {
  513. X                        $$ = 0;
  514. X                        yyerror();
  515. X                      }
  516. X                    }
  517. X        ;
  518. Xtbutton        : TBUTTON        { $$ = $1;
  519. X                      if ($1 == 0)
  520. X                        yyerror();
  521. X
  522. X                      if ($1 > MAX_BUTTONS)
  523. X                      {
  524. X                        $$ = 0;
  525. X                        yyerror();
  526. X                      }
  527. X                    }
  528. X        ;
  529. X
  530. Xstring        : STRING        { ptr = (char *)malloc(strlen($1)+1);
  531. X                      strcpy(ptr, $1);
  532. X                      RemoveDQuote(ptr);
  533. X                      $$ = ptr;
  534. X                    }
  535. Xnumber        : NUMBER        { $$ = $1; }
  536. X        ;
  537. X
  538. X%%
  539. Xyyerror(s) char *s;
  540. X{
  541. X    fprintf(stderr, "twm: syntax error, line %d\n", yylineno);
  542. X    ParseError = 1;
  543. X}
  544. XRemoveDQuote(str)
  545. Xchar *str;
  546. X{
  547. X    strcpy(str, &str[1]);
  548. X    str[strlen(str)-1] = '\0';
  549. X}
  550. X
  551. XMenuRoot *
  552. XGetRoot(name)
  553. Xchar *name;
  554. X{
  555. X    MenuRoot *tmp;
  556. X
  557. X    tmp = FindMenuRoot(name);
  558. X    if (tmp == NULL)
  559. X    tmp = NewMenuRoot(name);
  560. X
  561. X    return tmp;
  562. X}
  563. X
  564. SHAR_EOF
  565. if test 6242 -ne "`wc -c < gram.y`"
  566. then
  567.     echo shar: error transmitting "gram.y" '(should have been 6242 characters)'
  568. fi
  569. fi
  570. if test -f 'lex.l'
  571. then
  572.     echo shar: will not over-write existing file "lex.l"
  573. else
  574. echo extracting "lex.l"
  575. sed 's/^X//' >lex.l <<'SHAR_EOF'
  576. X%{
  577. X/*****************************************************************************/
  578. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  579. X/**                          Salt Lake City, Utah                           **/
  580. X/**                                                                         **/
  581. X/**                           All Rights Reserved                           **/
  582. X/**                                                                         **/
  583. X/**    Permission to use, copy, modify, and distribute this software and    **/
  584. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  585. X/**    granted, provided that the above copyright notice appear  in  all    **/
  586. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  587. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  588. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  589. X/**    city pertaining to distribution  of the software without  specif-    **/
  590. X/**    ic, written prior permission.                                        **/
  591. X/**                                                                         **/
  592. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  593. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  594. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  595. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  596. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  597. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  598. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  599. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  600. X/*****************************************************************************/
  601. X
  602. X/***********************************************************************
  603. X *
  604. X * $Header: lex.l,v 1.19 88/04/15 07:09:32 tlastran Exp $
  605. X *
  606. X * .twmrc lex file
  607. X *
  608. X * 12-Nov-87 Thomas E. LaStrange        File created
  609. X *
  610. X ***********************************************************************/
  611. X
  612. Xstatic char RCSinfo[]=
  613. X"$Header: lex.l,v 1.19 88/04/15 07:09:32 tlastran Exp $";
  614. X
  615. X#include <stdio.h>
  616. X#include "gram.h"
  617. X
  618. Xextern int ParseError;
  619. X
  620. X%}
  621. Xqstring                \"[^"]*\"
  622. Xnumber                [0-9]+
  623. Xbutton                [Bb][Uu][Tt][Tt][Oo][Nn]
  624. Xtbutton                [Tt][Ii][Tt][Ll][Ee][Bb][Uu][Tt][Tt][Oo][Nn]
  625. X%%
  626. X"{"                { return LB; }
  627. X"}"                { return RB; }
  628. X
  629. X{button}{number}        { (void)sscanf(&yytext[6], "%d", &yylval.num);
  630. X                  return (BUTTON);
  631. X                }
  632. X{tbutton}{number}        { (void)sscanf(&yytext[11], "%d", &yylval.num);
  633. X                  return (TBUTTON);
  634. X                }
  635. X[Mm][Ee][Nn][Uu]        { return MENU; }
  636. X
  637. Xf.nop                { return F_NOP; }
  638. Xf.quit                { return F_QUIT; }
  639. Xf.title                { return F_TITLE ; }
  640. Xf.menu                { return F_MENU; }
  641. Xf.focus                { return F_FOCUS; }
  642. Xf.refresh            { return F_REFRESH; }
  643. Xf.file                { return F_FILE; }
  644. Xf.twmrc                { return F_TWMRC; }
  645. Xf.version            { return F_VERSION; }
  646. Xf.circleup            { return F_CIRCLEUP; }
  647. Xf.circledown            { return F_CIRCLEDOWN; }
  648. Xf.source            { return F_SOURCE; }
  649. Xf.cutfile            { return F_CUTFILE; }
  650. X"!"                { return F_EXEC; }
  651. X"^"                { return F_CUT; }
  652. X
  653. Xt.nop                { return T_NOP; }
  654. Xt.raise                { return T_RAISE; }
  655. Xt.lower                { return T_LOWER; }
  656. Xt.move                { return T_MOVE; }
  657. X
  658. X[Uu][Nn][Kk][Nn][Oo][Ww][Nn][Ii][Cc][Oo][Nn] { return UNKNOWN_ICON; }
  659. X[Ww][Aa][Rr][Pp][Cc][Uu][Rr][Ss][Oo][Rr] { return WARPCURSOR; }
  660. X[Bb][Oo][Rr][Dd][Ee][Rr][Ww][Ii][Dd][Tt][Hh] { return BORDERWIDTH; }
  661. X[Tt][Ii][Tt][Ll][Ee][Ff][Oo][Nn][Tt] { return (TITLE_FONT); }
  662. X[Mm][Ee][Nn][Uu][Ff][Oo][Nn][Tt] { return (MENU_FONT); }
  663. X[Ii][Cc][Oo][Nn][Ff][Oo][Nn][Tt] { return (ICON_FONT); }
  664. X[Rr][Ee][Ss][Ii][Zz][Ee][Ff][Oo][Nn][Tt] { return (RESIZE_FONT); }
  665. X[Rr][Ee][Vv][Ee][Rr][Ss][Ee][Vv][Ii][Dd][Ee][Oo] { return (REVERSE_VIDEO); }
  666. X[Nn][Oo][Tt][Ii][Tt][Ll][Ee]    { return (NO_TITLE); }
  667. X[Aa][Uu][Tt][Oo][Rr][Aa][Ii][Ss][Ee]    { return (AUTO_RAISE); }
  668. X
  669. X{qstring}            { yylval.ptr = yytext; return STRING; }
  670. X{number}            { (void)sscanf(yytext, "%d", &yylval.num);
  671. X                  return (NUMBER);
  672. X                }
  673. X\#[^\n]*\n            {;}
  674. X[\n\t ]                {;}
  675. X.                {
  676. X                  fprintf(stderr,
  677. X                    "twm: bad character `%s', line %d\n",
  678. X                    yytext, yylineno);
  679. X                  ParseError = 1;
  680. X                }
  681. X%%
  682. Xyywrap() { return(1);}
  683. X
  684. X#define unput(c)    TwmUnput(c)
  685. X#define input()        TwmInput()
  686. X#define output(c)    TwmOutput(c)
  687. SHAR_EOF
  688. if test 4392 -ne "`wc -c < lex.l`"
  689. then
  690.     echo shar: error transmitting "lex.l" '(should have been 4392 characters)'
  691. fi
  692. fi
  693. if test -f 'add_window.c'
  694. then
  695.     echo shar: will not over-write existing file "add_window.c"
  696. else
  697. echo extracting "add_window.c"
  698. sed 's/^X//' >add_window.c <<'SHAR_EOF'
  699. X/*****************************************************************************/
  700. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  701. X/**                          Salt Lake City, Utah                           **/
  702. X/**                                                                         **/
  703. X/**                           All Rights Reserved                           **/
  704. X/**                                                                         **/
  705. X/**    Permission to use, copy, modify, and distribute this software and    **/
  706. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  707. X/**    granted, provided that the above copyright notice appear  in  all    **/
  708. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  709. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  710. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  711. X/**    city pertaining to distribution  of the software without  specif-    **/
  712. X/**    ic, written prior permission.                                        **/
  713. X/**                                                                         **/
  714. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  715. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  716. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  717. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  718. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  719. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  720. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  721. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  722. X/*****************************************************************************/
  723. X
  724. X/**********************************************************************
  725. X *
  726. X * $Header: add_window.c,v 1.7 88/04/15 07:10:05 tlastran Exp $
  727. X *
  728. X * Add a new window, put the titlbar and other stuff around
  729. X * the window
  730. X *
  731. X * 31-Mar-88 Tom LaStrange        Initial Version.
  732. X *
  733. X **********************************************************************/
  734. X
  735. X#ifndef lint
  736. Xstatic char RCSinfo[]=
  737. X"$Header: add_window.c,v 1.7 88/04/15 07:10:05 tlastran Exp $";
  738. X#endif lint
  739. X
  740. X#include <stdio.h>
  741. X#include "twm.h"
  742. X#include "util.h"
  743. X#include "resize.h"
  744. X#include "gram.h"
  745. X#include "list.h"
  746. X
  747. X#include "iconify.bm"
  748. X#include "resize.bm"
  749. X#include "xterm.bm"
  750. X#include "focus.bm"
  751. X#include "hilite.bm"
  752. X
  753. Xstatic char NoName[] = "No Name"; /* name if no name is specified */
  754. X
  755. X/***********************************************************************
  756. X *
  757. X *  Procedure:
  758. X *    AddWindow - add a new window to the twm list
  759. X *
  760. X *  Returned Value:
  761. X *    (TwmWindow *) - pointer to the TwmWindow structure
  762. X *
  763. X *  Inputs:
  764. X *    w    - the window id of the window to add
  765. X *
  766. X ***********************************************************************
  767. X */
  768. X
  769. XTwmWindow *
  770. XAddWindow(w)
  771. XWindow w;
  772. X{
  773. X    TwmWindow *tmp_win;            /* new twm window structure */
  774. X    unsigned long valuemask;        /* mask for create windows */
  775. X    XSetWindowAttributes attributes;    /* attributes for create windows */
  776. X    int icon_width;        /* width of the icon pixmap */
  777. X    int icon_height;        /* height of the icon pixmap */
  778. X    int width;            /* tmp variable */
  779. X    int x;
  780. X    Pixmap pm;            /* tmp pixmap variable */
  781. X    XWindowChanges xwc;        /* change window structure */
  782. X    unsigned int xwcm;        /* change window mask */
  783. X
  784. X#ifdef DEBUG
  785. X    fprintf(stderr, "AddWindow: w = 0x%x\n", w);
  786. X#endif
  787. X
  788. X    /* allocate space for the twm window */
  789. X    tmp_win = (TwmWindow *)malloc(sizeof(TwmWindow));
  790. X    tmp_win->w = w;
  791. X
  792. X    XGetWindowAttributes(dpy, tmp_win->w, &tmp_win->attr);
  793. X    XFetchName(dpy, tmp_win->w, &tmp_win->name);
  794. X#ifdef DEBUG
  795. X    fprintf(stderr, "  name = \"%s\"\n", tmp_win->name);
  796. X#endif
  797. X    tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w);
  798. X    if (XGetNormalHints(dpy, tmp_win->w, &tmp_win->hints) == 0)
  799. X    tmp_win->hints.flags = 0;
  800. X
  801. X    if (tmp_win->hints.flags & PSize)
  802. X    {
  803. X#ifdef DEBUG
  804. X    fprintf(stderr, "  program specified hints\n");
  805. X#endif
  806. X    tmp_win->attr.x = tmp_win->hints.x;
  807. X    tmp_win->attr.y = tmp_win->hints.y;
  808. X    tmp_win->attr.width = tmp_win->hints.width;
  809. X    tmp_win->attr.height = tmp_win->hints.height;
  810. X    }
  811. X    if (tmp_win->hints.flags & USSize)
  812. X    {
  813. X#ifdef DEBUG
  814. X    fprintf(stderr, "  user specified hints\n");
  815. X#endif
  816. X    tmp_win->attr.x = tmp_win->hints.x;
  817. X    tmp_win->attr.y = tmp_win->hints.y;
  818. X    tmp_win->attr.width = tmp_win->hints.width;
  819. X    tmp_win->attr.height = tmp_win->hints.height;
  820. X    }
  821. X
  822. X    if (tmp_win->name == NULL)
  823. X    tmp_win->name = NoName;
  824. X
  825. X    tmp_win->auto_raise = LookInList(AUTO_RAISE, tmp_win->name);
  826. X    if (LookInList(NO_TITLE, tmp_win->name))
  827. X    {
  828. X    tmp_win->title_height = 0;
  829. X    }
  830. X    else
  831. X    {
  832. X    tmp_win->title_height = TITLE_BAR_HEIGHT + BorderWidth;
  833. X    }
  834. X
  835. X    if (tmp_win->attr.y < tmp_win->title_height)
  836. X    tmp_win->attr.y = tmp_win->title_height;
  837. X
  838. X    xwcm = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
  839. X
  840. X#ifdef DEBUG
  841. X    fprintf(stderr, "  position window  %d, %d  %dx%d\n", 
  842. X        tmp_win->attr.x,
  843. X        tmp_win->attr.y,
  844. X        tmp_win->attr.width,
  845. X        tmp_win->attr.height);
  846. X#endif
  847. X    xwc.x = tmp_win->attr.x + tmp_win->attr.border_width;
  848. X    xwc.y = tmp_win->attr.y + tmp_win->attr.border_width;
  849. X    xwc.width = tmp_win->attr.width;
  850. X    xwc.height = tmp_win->attr.height;
  851. X    xwc.border_width = 0;
  852. X
  853. X    XConfigureWindow(dpy, tmp_win->w, xwcm, &xwc);
  854. X
  855. X
  856. X    tmp_win->full_name = tmp_win->name;
  857. X
  858. X    if (strncmp("xterm", tmp_win->name, 5) == 0 ||
  859. X    strncmp("yterm", tmp_win->name, 5) == 0 ||
  860. X    strncmp("console", tmp_win->name, 7) == 0 ||
  861. X    strncmp("login", tmp_win->name, 5) == 0)
  862. X    tmp_win->xterm = TRUE;
  863. X    else
  864. X    tmp_win->xterm = FALSE;
  865. X
  866. X    if (strncmp("xterm_", tmp_win->name, 6) == 0)
  867. X    tmp_win->name = &tmp_win->name[6];
  868. X
  869. X    tmp_win->name_width = XTextWidth(TitleBarFont, tmp_win->name,
  870. X    strlen(tmp_win->name));
  871. X    tmp_win->icon_name = tmp_win->name;
  872. X
  873. X    tmp_win->iconified = FALSE;
  874. X    tmp_win->icon = FALSE;
  875. X
  876. X    /* add the window into the twm list */
  877. X    tmp_win->next = TwmRoot.next;
  878. X    if (TwmRoot.next != NULL)
  879. X    TwmRoot.next->prev = tmp_win;
  880. X    tmp_win->prev = &TwmRoot;
  881. X    TwmRoot.next = tmp_win;
  882. X
  883. X    /* create windows */
  884. X
  885. X    tmp_win->frame_x = tmp_win->attr.x;
  886. X    tmp_win->frame_y = tmp_win->attr.y - tmp_win->title_height;
  887. X
  888. X    tmp_win->frame = XCreateSimpleWindow(dpy, Root,
  889. X    tmp_win->frame_x,
  890. X    tmp_win->frame_y,
  891. X    tmp_win->attr.width,
  892. X    tmp_win->attr.height + tmp_win->title_height,
  893. X    BorderWidth,
  894. X    Foreground, Background);
  895. X
  896. X    tmp_win->title_w = XCreateSimpleWindow(dpy, tmp_win->frame,
  897. X    -BorderWidth, -BorderWidth,
  898. X    tmp_win->attr.width, TITLE_BAR_HEIGHT,
  899. X    BorderWidth,
  900. X    Foreground, Background);
  901. X
  902. X    /* the three buttons have the pixmap as the background of the
  903. X     * window, that way I don't have to worry about repainting them
  904. X     * on expose events.
  905. X     */
  906. X
  907. X    valuemask = CWEventMask | CWBackPixmap;
  908. X    attributes.event_mask = ButtonPressMask;
  909. X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
  910. X    iconify_bits, iconify_width, iconify_height);
  911. X
  912. X    tmp_win->iconify_w = XCreateWindow(dpy, tmp_win->title_w,
  913. X    TITLE_BAR_SPACE, TITLE_BAR_SPACE,
  914. X    iconify_width, iconify_height,
  915. X    0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
  916. X    valuemask, &attributes);
  917. X
  918. X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
  919. X    focus_bits, focus_width, focus_height);
  920. X
  921. X    tmp_win->focus_w = XCreateWindow(dpy, tmp_win->title_w,
  922. X    tmp_win->attr.width - resize_width -3 - focus_width, TITLE_BAR_SPACE,
  923. X    iconify_width, iconify_height,
  924. X    0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
  925. X    valuemask, &attributes);
  926. X
  927. X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
  928. X    resize_bits, resize_width, resize_height);
  929. X
  930. X    tmp_win->resize_w = XCreateWindow(dpy, tmp_win->title_w,
  931. X    tmp_win->attr.width - resize_width - 1,
  932. X    TITLE_BAR_SPACE,
  933. X    resize_width, resize_height,
  934. X    0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
  935. X    valuemask, &attributes);
  936. X    
  937. X    valuemask = CWBackPixmap;
  938. X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
  939. X    hilite_bits, hilite_width, hilite_height);
  940. X
  941. X    tmp_win->hilite_w = XCreateWindow(dpy, tmp_win->title_w,
  942. X    TitleBarX, 1,
  943. X    10, hilite_height,
  944. X    0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
  945. X    valuemask, &attributes);
  946. X    
  947. X    XDefineCursor(dpy, tmp_win->title_w, ArrowCursor);
  948. X    XDefineCursor(dpy, tmp_win->iconify_w, ButtonCursor);
  949. X    XDefineCursor(dpy, tmp_win->focus_w, ButtonCursor);
  950. X    XDefineCursor(dpy, tmp_win->resize_w, ButtonCursor);
  951. X
  952. X    XSelectInput(dpy, tmp_win->w, StructureNotifyMask);
  953. X    XSelectInput(dpy, tmp_win->frame,
  954. X    ButtonPressMask | EnterWindowMask | LeaveWindowMask);
  955. X
  956. X    XSelectInput(dpy, tmp_win->title_w, 
  957. X    ButtonPressMask | ButtonReleaseMask |
  958. X    ExposureMask | ButtonMotionMask);
  959. X
  960. X    XAddToSaveSet(dpy, tmp_win->w);
  961. X    XReparentWindow(dpy, tmp_win->w, tmp_win->frame, 0, tmp_win->title_height);
  962. X
  963. X    SetupWindow(tmp_win,
  964. X    tmp_win->frame_x,
  965. X    tmp_win->frame_y,
  966. X    tmp_win->attr.width,
  967. X    tmp_win->attr.height + tmp_win->title_height);
  968. X
  969. X    pm = NULL;
  970. X    if (tmp_win->wmhints && tmp_win->wmhints->flags & IconPixmapHint)
  971. X    {
  972. X    XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap,
  973. X        &JunkRoot, &JunkX, &JunkY,
  974. X        &icon_width, &icon_height, &JunkBW,
  975. X        &JunkDepth);
  976. X
  977. X    pm = XCreatePixmap(dpy, Root, icon_width, icon_height,
  978. X        DefaultDepth(dpy, 0));
  979. X
  980. X    XCopyPlane(dpy, tmp_win->wmhints->icon_pixmap, pm, MenuNormalGC,
  981. X        0,0, icon_width, icon_height, 0, 0, 1 );
  982. X    }
  983. X    else
  984. X    {
  985. X    if (tmp_win->xterm)
  986. X    {
  987. X        pm = MakePixmap(Root, MenuNormalGC,
  988. X        xterm_bits, xterm_width, xterm_height);
  989. X        icon_width = xterm_width;
  990. X        icon_height = xterm_height;
  991. X    }
  992. X    else if (UnknownPm != NULL)
  993. X    {
  994. X        XImage *image;
  995. X        unsigned mask;
  996. X
  997. X        icon_width = UnknownWidth;
  998. X        icon_height = UnknownHeight;
  999. X        mask = Foreground ^ Background;
  1000. X        image = XGetImage(dpy, UnknownPm, 0, 0, icon_width, icon_height,
  1001. X        mask, XYPixmap);
  1002. X
  1003. X        pm = XCreatePixmap(dpy, Root, icon_width, icon_height,
  1004. X        DefaultDepth(dpy, 0));
  1005. X
  1006. X        XPutImage(dpy, pm, TitleNormalGC,
  1007. X        image, 0, 0, 0, 0, icon_width, icon_height);
  1008. X    }
  1009. X    }
  1010. X
  1011. X    if (pm == NULL)
  1012. X    {
  1013. X    icon_height = 0;
  1014. X    icon_width = 0;
  1015. X    valuemask = 0;
  1016. X    }
  1017. X    else
  1018. X    {
  1019. X    valuemask = CWBackPixmap;
  1020. X    attributes.background_pixmap = pm;
  1021. X    }
  1022. X
  1023. X    width = XTextWidth(IconFont,
  1024. X    tmp_win->icon_name, strlen(tmp_win->icon_name));
  1025. X
  1026. X    width += 6;
  1027. X    if (width < icon_width)
  1028. X    {
  1029. X    tmp_win->icon_x = (icon_width - width)/2;
  1030. X    tmp_win->icon_x += 3;
  1031. X    width = icon_width;
  1032. X    }
  1033. X    else
  1034. X    {
  1035. X    tmp_win->icon_x = 3;
  1036. X    }
  1037. X    tmp_win->icon_y = icon_height + IconFontHeight;
  1038. X
  1039. X    if (tmp_win->wmhints && tmp_win->wmhints->flags & IconWindowHint)
  1040. X    {
  1041. X    tmp_win->icon_w = tmp_win->wmhints->icon_window;
  1042. X    }
  1043. X    else
  1044. X    {
  1045. X    tmp_win->icon_w = XCreateSimpleWindow(dpy, Root,
  1046. X        0,0,
  1047. X        width,
  1048. X        icon_height + IconFontHeight + 4,
  1049. X        2, Foreground, Background);
  1050. X    }
  1051. X
  1052. X    XSelectInput(dpy, tmp_win->icon_w,
  1053. X    ButtonPressMask | ExposureMask);
  1054. X
  1055. X    if (pm != NULL)
  1056. X    {
  1057. X    if (width == icon_width)
  1058. X        x = 0;
  1059. X    else
  1060. X        x = (width - icon_width)/2;
  1061. X
  1062. X    XCreateWindow(dpy, tmp_win->icon_w,
  1063. X        x, 0,
  1064. X        icon_width, icon_height,
  1065. X        0, DefaultDepth(dpy, 0), CopyFromParent,
  1066. X        DefaultVisual(dpy,0),
  1067. X        valuemask, &attributes);
  1068. X    }
  1069. X
  1070. X    XDefineCursor(dpy, tmp_win->icon_w, ArrowCursor);
  1071. X
  1072. X    XSaveContext(dpy, tmp_win->w, TwmContext, tmp_win);
  1073. X    XSaveContext(dpy, tmp_win->frame, TwmContext, tmp_win);
  1074. X    XSaveContext(dpy, tmp_win->title_w, TwmContext, tmp_win);
  1075. X    XSaveContext(dpy, tmp_win->iconify_w, TwmContext, tmp_win);
  1076. X    XSaveContext(dpy, tmp_win->resize_w, TwmContext, tmp_win);
  1077. X    XSaveContext(dpy, tmp_win->icon_w, TwmContext, tmp_win);
  1078. X    XSaveContext(dpy, tmp_win->focus_w, TwmContext, tmp_win);
  1079. X    XSaveContext(dpy, tmp_win->hilite_w, TwmContext, tmp_win);
  1080. X
  1081. X    return (tmp_win);
  1082. X}
  1083. X
  1084. X/***********************************************************************
  1085. X *
  1086. X *  Procedure:
  1087. X *    MappedNotOverride - checks to see if we should really
  1088. X *        put a twm frame on the window
  1089. X *
  1090. X *  Returned Value:
  1091. X *    TRUE    - go ahead and frame the window
  1092. X *    FALSE    - don't frame the window
  1093. X *
  1094. X *  Inputs:
  1095. X *    w    - the window to check
  1096. X *
  1097. X ***********************************************************************
  1098. X */
  1099. X
  1100. Xint
  1101. XMappedNotOverride(w)
  1102. X    Window w;
  1103. X{
  1104. X    XWindowAttributes wa;
  1105. X
  1106. X    XGetWindowAttributes(dpy, w, &wa);
  1107. X    return ((wa.map_state != IsUnmapped) && (wa.override_redirect != True));
  1108. X}
  1109. SHAR_EOF
  1110. if test 12604 -ne "`wc -c < add_window.c`"
  1111. then
  1112.     echo shar: error transmitting "add_window.c" '(should have been 12604 characters)'
  1113. fi
  1114. fi
  1115. if test -f 'gc.c'
  1116. then
  1117.     echo shar: will not over-write existing file "gc.c"
  1118. else
  1119. echo extracting "gc.c"
  1120. sed 's/^X//' >gc.c <<'SHAR_EOF'
  1121. X/*****************************************************************************/
  1122. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  1123. X/**                          Salt Lake City, Utah                           **/
  1124. X/**                                                                         **/
  1125. X/**                           All Rights Reserved                           **/
  1126. X/**                                                                         **/
  1127. X/**    Permission to use, copy, modify, and distribute this software and    **/
  1128. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  1129. X/**    granted, provided that the above copyright notice appear  in  all    **/
  1130. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  1131. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  1132. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  1133. X/**    city pertaining to distribution  of the software without  specif-    **/
  1134. X/**    ic, written prior permission.                                        **/
  1135. X/**                                                                         **/
  1136. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  1137. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  1138. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  1139. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  1140. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  1141. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  1142. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  1143. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  1144. X/*****************************************************************************/
  1145. X
  1146. X/**********************************************************************
  1147. X *
  1148. X * $Header: gc.c,v 1.3 88/04/15 07:09:38 tlastran Exp $
  1149. X *
  1150. X * Open the fonts and create the GCs
  1151. X *
  1152. X * 31-Mar-88 Tom LaStrange        Initial Version.
  1153. X *
  1154. X **********************************************************************/
  1155. X
  1156. X#ifndef lint
  1157. Xstatic char RCSinfo[]=
  1158. X"$Header: gc.c,v 1.3 88/04/15 07:09:38 tlastran Exp $";
  1159. X#endif lint
  1160. X
  1161. X#include <stdio.h>
  1162. X#include "twm.h"
  1163. X
  1164. X/***********************************************************************
  1165. X *
  1166. X *  Procedure:
  1167. X *    CreateGCs - open fonts and create all the needed GC's.  I only
  1168. X *            want to do this once, hence the first_time flag.
  1169. X *
  1170. X ***********************************************************************
  1171. X */
  1172. X
  1173. Xvoid
  1174. XCreateGCs()
  1175. X{
  1176. X    static int first_time = TRUE;
  1177. X    XGCValues        gcv;
  1178. X    unsigned long   gcm, mask;
  1179. X
  1180. X    if (!first_time)
  1181. X    return;
  1182. X
  1183. X    first_time = FALSE;
  1184. X
  1185. X    /* open fonts */
  1186. X
  1187. X    TitleBarFont = XLoadQueryFont(dpy, TitleBarFontName);
  1188. X    TitleBarFontHeight = TitleBarFont->ascent + TitleBarFont->descent;
  1189. X    if (TitleBarFontHeight < TITLE_BAR_FONT_HEIGHT)
  1190. X    {
  1191. X    TitleBarY = (TITLE_BAR_FONT_HEIGHT - TitleBarFontHeight)/2 +
  1192. X        TITLE_BAR_SPACE + TitleBarFont->ascent;
  1193. X    }
  1194. X    else
  1195. X    {
  1196. X    TitleBarY = TITLE_BAR_SPACE + TitleBarFont->ascent;
  1197. X    }
  1198. X
  1199. X    MenuFont = XLoadQueryFont(dpy, MenuFontName);
  1200. X    MenuFontHeight = MenuFont->ascent + MenuFont->descent;
  1201. X    MenuY = MenuFont->ascent + 1;
  1202. X
  1203. X    IconFont = XLoadQueryFont(dpy, IconFontName);
  1204. X    IconFontHeight = IconFont->ascent + IconFont->descent;
  1205. X
  1206. X    VersionFont = XLoadQueryFont(dpy, VersionFontName);
  1207. X    VersionFontHeight = VersionFont->ascent + VersionFont->descent;
  1208. X
  1209. X    SizeFont = XLoadQueryFont(dpy, SizeFontName);
  1210. X    SizeFontHeight = SizeFont->ascent + SizeFont->descent;
  1211. X
  1212. X    /* create GC's */
  1213. X
  1214. X    if (ReverseVideo)
  1215. X    {
  1216. X    Background = BlackPixel(dpy, DefaultScreen(dpy));
  1217. X    Foreground = WhitePixel(dpy, DefaultScreen(dpy));
  1218. X    }
  1219. X    else
  1220. X    {
  1221. X    Foreground = BlackPixel(dpy, DefaultScreen(dpy));
  1222. X    Background = WhitePixel(dpy, DefaultScreen(dpy));
  1223. X    }
  1224. X    mask = Foreground ^ Background;
  1225. X
  1226. X    gcm = 0;
  1227. X    gcm |= GCFont;        gcv.font = TitleBarFont->fid;
  1228. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1229. X    gcm |= GCForeground;    gcv.foreground = Foreground;
  1230. X    gcm |= GCBackground;    gcv.background = Background;
  1231. X
  1232. X    TitleNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  1233. X
  1234. X    gcm = 0;
  1235. X    gcm |= GCFont;        gcv.font = MenuFont->fid;
  1236. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1237. X    gcm |= GCForeground;    gcv.foreground = Foreground;
  1238. X    gcm |= GCBackground;    gcv.background = Background;
  1239. X
  1240. X    MenuNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  1241. X
  1242. X    gcv.foreground = Background;
  1243. X    gcv.background = Foreground;
  1244. X
  1245. X    MenuReverseGC = XCreateGC(dpy, Root, gcm, &gcv);
  1246. X
  1247. X    gcm = 0;
  1248. X    gcm |= GCFunction;        gcv.function = GXxor;
  1249. X    gcm |= GCFont;        gcv.font = MenuFont->fid;
  1250. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1251. X    gcm |= GCForeground;    gcv.foreground = mask;
  1252. X    gcm |= GCBackground;    gcv.background = Background;
  1253. X
  1254. X    MenuXorGC = XCreateGC(dpy, Root, gcm, &gcv);
  1255. X
  1256. X    gcm = 0;
  1257. X    gcm |= GCFunction;        gcv.function = GXxor;
  1258. X    gcm |= GCLineWidth;        gcv.line_width = 0;
  1259. X    gcm |= GCForeground;    gcv.foreground = mask;
  1260. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1261. X    gcm |= GCSubwindowMode; gcv.subwindow_mode = IncludeInferiors;
  1262. X
  1263. X    DrawGC = XCreateGC(dpy, Root, gcm, &gcv);
  1264. X
  1265. X    gcm = 0;
  1266. X    gcm |= GCFont;        gcv.font = IconFont->fid;
  1267. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1268. X    gcm |= GCForeground;    gcv.foreground = Foreground;
  1269. X    gcm |= GCBackground;    gcv.background = Background;
  1270. X
  1271. X    IconNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  1272. X
  1273. X    gcm = 0;
  1274. X    gcm |= GCFont;        gcv.font = VersionFont->fid;
  1275. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1276. X    gcm |= GCForeground;    gcv.foreground = Foreground;
  1277. X    gcm |= GCBackground;    gcv.background = Background;
  1278. X
  1279. X    VersionNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  1280. X
  1281. X    gcm = 0;
  1282. X    gcm |= GCFont;        gcv.font = SizeFont->fid;
  1283. X    gcm |= GCPlaneMask;        gcv.plane_mask = mask;
  1284. X    gcm |= GCForeground;    gcv.foreground = Foreground;
  1285. X    gcm |= GCBackground;    gcv.background = Background;
  1286. X
  1287. X    SizeNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
  1288. X}
  1289. SHAR_EOF
  1290. if test 6215 -ne "`wc -c < gc.c`"
  1291. then
  1292.     echo shar: error transmitting "gc.c" '(should have been 6215 characters)'
  1293. fi
  1294. fi
  1295. if test -f 'list.c'
  1296. then
  1297.     echo shar: will not over-write existing file "list.c"
  1298. else
  1299. echo extracting "list.c"
  1300. sed 's/^X//' >list.c <<'SHAR_EOF'
  1301. X/*****************************************************************************/
  1302. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  1303. X/**                          Salt Lake City, Utah                           **/
  1304. X/**                                                                         **/
  1305. X/**                           All Rights Reserved                           **/
  1306. X/**                                                                         **/
  1307. X/**    Permission to use, copy, modify, and distribute this software and    **/
  1308. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  1309. X/**    granted, provided that the above copyright notice appear  in  all    **/
  1310. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  1311. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  1312. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  1313. X/**    city pertaining to distribution  of the software without  specif-    **/
  1314. X/**    ic, written prior permission.                                        **/
  1315. X/**                                                                         **/
  1316. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  1317. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  1318. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  1319. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  1320. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  1321. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  1322. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  1323. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  1324. X/*****************************************************************************/
  1325. X
  1326. X/**********************************************************************
  1327. X *
  1328. X * $Header: list.c,v 1.2 88/04/15 07:09:53 tlastran Exp $
  1329. X *
  1330. X * TWM code to deal with the name lists for the NoTitle list and
  1331. X * the AutoRaise list
  1332. X *
  1333. X * 11-Apr-88 Tom LaStrange        Initial Version.
  1334. X *
  1335. X **********************************************************************/
  1336. X
  1337. X#ifndef lint
  1338. Xstatic char RCSinfo[]=
  1339. X"$Header: list.c,v 1.2 88/04/15 07:09:53 tlastran Exp $";
  1340. X#endif lint
  1341. X
  1342. X#include <stdio.h>
  1343. X#include "twm.h"
  1344. X#include "gram.h"
  1345. X
  1346. Xtypedef struct name_list name_list;
  1347. X
  1348. Xstruct name_list
  1349. X{
  1350. X    name_list *next;        /* pointer to the next name */
  1351. X    char *name;            /* the name of the window */
  1352. X};
  1353. X
  1354. Xname_list *NoTitle = NULL;    /* list of window names with no title bar */
  1355. Xname_list *AutoRaise = NULL;    /* list of window names to auto-raise */
  1356. X
  1357. X/***********************************************************************
  1358. X *
  1359. X *  Procedure:
  1360. X *    AddToList - add a window name to the appropriate list
  1361. X *
  1362. X *  Inputs:
  1363. X *    list    - a #define to identify the list
  1364. X *    name    - a pointer to the name of the window 
  1365. X *
  1366. X ***********************************************************************
  1367. X */
  1368. X
  1369. Xvoid
  1370. XAddToList(list, name)
  1371. Xint list;
  1372. Xchar *name;
  1373. X{
  1374. X    name_list *ptr;
  1375. X
  1376. X    ptr = (name_list *)malloc(sizeof(name_list));
  1377. X    if (ptr == NULL)
  1378. X    {
  1379. X    fprintf(stderr, "twm: out of memory\n");
  1380. X    exit(1);
  1381. X    }
  1382. X
  1383. X    ptr->name = name;
  1384. X
  1385. X    switch (list)
  1386. X    {
  1387. X    case AUTO_RAISE:
  1388. X    ptr->next = AutoRaise;
  1389. X    AutoRaise = ptr;
  1390. X    break;
  1391. X
  1392. X    case NO_TITLE:
  1393. X    ptr->next = NoTitle;
  1394. X    NoTitle = ptr;
  1395. X    break;
  1396. X    }
  1397. X}
  1398. X
  1399. X/***********************************************************************
  1400. X *
  1401. X *  Procedure:
  1402. X *    LookInList - look through a list for a window name
  1403. X *
  1404. X *  Returned Value:
  1405. X *    TRUE    - the window was found in the list
  1406. X *    FALSE    - the window was not found in the list
  1407. X *
  1408. X *  Inputs:
  1409. X *    list    - a #define to identify the list
  1410. X *    name    - a pointer to the name to look for
  1411. X *
  1412. X ***********************************************************************
  1413. X */
  1414. X
  1415. Xint
  1416. XLookInList(list, name)
  1417. Xint list;
  1418. Xchar *name;
  1419. X{
  1420. X    name_list *l;
  1421. X    name_list *ptr;
  1422. X
  1423. X    switch (list)
  1424. X    {
  1425. X    case AUTO_RAISE:
  1426. X    l = AutoRaise;
  1427. X    break;
  1428. X
  1429. X    case NO_TITLE:
  1430. X    l = NoTitle;
  1431. X    break;
  1432. X    }
  1433. X
  1434. X    for (ptr = l; ptr != NULL; ptr = ptr->next)
  1435. X    {
  1436. X    int len;
  1437. X
  1438. X    len = strlen(ptr->name);
  1439. X    if (strncmp(name, ptr->name, len) == 0)
  1440. X        return (TRUE);
  1441. X    }
  1442. X    return (FALSE);
  1443. X}
  1444. SHAR_EOF
  1445. if test 4301 -ne "`wc -c < list.c`"
  1446. then
  1447.     echo shar: error transmitting "list.c" '(should have been 4301 characters)'
  1448. fi
  1449. fi
  1450. if test -f 'twm.c'
  1451. then
  1452.     echo shar: will not over-write existing file "twm.c"
  1453. else
  1454. echo extracting "twm.c"
  1455. sed 's/^X//' >twm.c <<'SHAR_EOF'
  1456. X/*****************************************************************************/
  1457. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  1458. X/**                          Salt Lake City, Utah                           **/
  1459. X/**                                                                         **/
  1460. X/**                           All Rights Reserved                           **/
  1461. X/**                                                                         **/
  1462. X/**    Permission to use, copy, modify, and distribute this software and    **/
  1463. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  1464. X/**    granted, provided that the above copyright notice appear  in  all    **/
  1465. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  1466. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  1467. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  1468. X/**    city pertaining to distribution  of the software without  specif-    **/
  1469. X/**    ic, written prior permission.                                        **/
  1470. X/**                                                                         **/
  1471. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  1472. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  1473. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  1474. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  1475. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  1476. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  1477. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  1478. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  1479. X/*****************************************************************************/
  1480. X
  1481. X/***********************************************************************
  1482. X *
  1483. X * $Header: twm.c,v 1.23 88/04/15 07:09:30 tlastran Exp $
  1484. X *
  1485. X * twm - "Tom's Window Manager"
  1486. X *
  1487. X * 27-Oct-87 Thomas E. LaStrange    File created
  1488. X *
  1489. X ***********************************************************************/
  1490. X
  1491. X#ifndef lint
  1492. Xstatic char RCSinfo[] =
  1493. X"$Header: twm.c,v 1.23 88/04/15 07:09:30 tlastran Exp $";
  1494. X#endif
  1495. X
  1496. X#include <stdio.h>
  1497. X#include <signal.h>
  1498. X#include <fcntl.h>
  1499. X#include "twm.h"
  1500. X#include "add_window.h"
  1501. X#include "gc.h"
  1502. X#include "parse.h"
  1503. X#include "version.h"
  1504. X#include "menus.h"
  1505. X#include "events.h"
  1506. X#include "util.h"
  1507. X
  1508. X#include "twm.bm"
  1509. X
  1510. XTwmWindow TwmRoot;        /* the head of the twm window list */
  1511. X
  1512. XDisplay *dpy;            /* which display are we talking to */
  1513. X
  1514. XWindow Root;            /* the root window */
  1515. XWindow VersionWindow;        /* the twm version window */
  1516. XWindow SizeWindow;        /* the resize dimensions window */
  1517. XWindow ResizeWindow;        /* the window we are resizing */
  1518. X
  1519. XXFontStruct *TitleBarFont;    /* title bar font structure */
  1520. XXFontStruct *MenuFont;        /* menu font structure */
  1521. XXFontStruct *IconFont;        /* icon font structure */
  1522. XXFontStruct *SizeFont;        /* resize font structure */
  1523. XXFontStruct *VersionFont;    /* version font structure */
  1524. X
  1525. Xchar *TitleBarFontName = "8x13";/* default title bar font */
  1526. Xchar *MenuFontName = "8x13";    /* default menu font */
  1527. Xchar *IconFontName = "8x13";    /* default icon font */
  1528. Xchar *SizeFontName = "fg-22";    /* default resize font */
  1529. Xchar *VersionFontName = "8x13";    /* default version font */
  1530. X
  1531. Xint TitleBarFontHeight;        /* height of title bar font */
  1532. Xint MenuFontHeight;        /* height of menu font */
  1533. Xint IconFontHeight;        /* height of icon font */
  1534. Xint SizeFontHeight;        /* height of resize font */
  1535. Xint VersionFontHeight;        /* height of version font */
  1536. X
  1537. XCursor ArrowCursor;        /* title bar cursor */
  1538. XCursor ButtonCursor;        /* title bar button cursor */
  1539. XCursor MoveCursor;        /* move and resize cursor */
  1540. XCursor ClockCursor;        /* wait a while cursor */
  1541. XCursor RightArrowCursor;    /* menu cursor */
  1542. X
  1543. XGC TitleNormalGC;        /* GC for title bar */
  1544. XGC MenuNormalGC;        /* normal GC for menus */
  1545. XGC MenuReverseGC;        /* reverse video GC for menus */
  1546. XGC MenuXorGC;            /* XOR GC for menus */
  1547. XGC IconNormalGC;        /* GC for icons */
  1548. XGC VersionNormalGC;        /* GC for the version window */
  1549. XGC SizeNormalGC;        /* GC for the resize window */
  1550. XGC DrawGC;            /* GC to draw lines for move and resize */
  1551. X
  1552. XXContext TwmContext;        /* context for twm windows */
  1553. XXContext MenuContext;        /* context for all menu windows */
  1554. X
  1555. Xint BorderWidth = BW;        /* border width of twm windows */
  1556. Xunsigned long Foreground;    /* foreground color for all windows */
  1557. Xunsigned long Background;    /* background color for all windows */
  1558. X
  1559. Xchar Version[100];        /* place to build the version string */
  1560. XPixmap UnknownPm = NULL;    /* the unknown icon pixmap */
  1561. Xint UnknownWidth = 0;        /* width of the unknown icon */
  1562. Xint UnknownHeight = 0;        /* height of the unknown icon */
  1563. Xint FirstTime = TRUE;        /* first time we've read .twmrc */
  1564. Xint ReverseVideo = FALSE;    /* flag to do reverse video */
  1565. Xint FocusRoot = TRUE;        /* is the input focus on the root ? */
  1566. XTwmWindow *Focus = NULL;    /* the twm window that has focus */
  1567. Xint WarpCursor = FALSE;        /* warp cursor on de-iconify ? */
  1568. Xint ParseError;            /* error parsing the .twmrc file */
  1569. X
  1570. Xint TitleButton[MAX_BUTTONS + 1];    /* title button functions */
  1571. X
  1572. Xint TitleBarY;            /* y coordinate to start text in the title */
  1573. Xint TitleBarX = TITLE_BAR_HEIGHT + 4;    /* x coordinate ditto */
  1574. Xint MenuY;            /* y coordiante for text in menus */
  1575. X
  1576. XWindow JunkRoot;        /* junk window */
  1577. XWindow JunkChild;        /* junk window */
  1578. Xint JunkX;            /* junk variable */
  1579. Xint JunkY;            /* junk variable */
  1580. Xint JunkWidth;            /* junk variable */
  1581. Xint JunkHeight;            /* junk variable */
  1582. Xint JunkDepth;            /* junk variable */
  1583. Xint JunkBW;            /* junk variable */
  1584. Xint JunkMask;            /* junk variable */
  1585. X
  1586. X/***********************************************************************
  1587. X *
  1588. X *  Procedure:
  1589. X *    main - start of twm
  1590. X *
  1591. X ***********************************************************************
  1592. X */
  1593. X
  1594. Xmain(argc, argv)
  1595. X    int argc;
  1596. X    char *argv[];
  1597. X{
  1598. X    Window root, parent, *children;
  1599. X    int nchildren, i;
  1600. X    int m, d, y;
  1601. X    char *display_name;
  1602. X    unsigned long valuemask;    /* mask for create windows */
  1603. X    XSetWindowAttributes attributes;    /* attributes for create windows */
  1604. X
  1605. X    display_name = NULL;
  1606. X
  1607. X    if (argc != 1 && argc != 3)
  1608. X    {
  1609. X    fprintf(stderr, "Usage: twm [-display display]\n");
  1610. X    exit(1);
  1611. X    }
  1612. X
  1613. X    if (argc == 3)
  1614. X    {
  1615. X    if (strncmp(argv[1], "-d", 2) == 0)
  1616. X        display_name = argv[2];
  1617. X    else
  1618. X    {
  1619. X        fprintf(stderr, "Usage: twm [-display display]\n");
  1620. X        exit(1);
  1621. X    }
  1622. X    }
  1623. X
  1624. X    signal(SIGINT, Done);
  1625. X    signal(SIGQUIT, Done);
  1626. X    signal(SIGHUP, Done);
  1627. X    signal(SIGTERM, Done);
  1628. X
  1629. X    TwmRoot.next = NULL;
  1630. X    TwmRoot.prev = NULL;
  1631. X    TwmRoot.w = NULL;
  1632. X    TwmRoot.title_w = NULL;
  1633. X    TwmRoot.iconify_w = NULL;
  1634. X    TwmRoot.resize_w = NULL;
  1635. X
  1636. X    if ((dpy = XOpenDisplay(display_name)) == NULL)
  1637. X    {
  1638. X    fprintf(stderr, "twm: can't open the display\n");
  1639. X    exit(1);
  1640. X    }
  1641. X
  1642. X
  1643. X    if (fcntl(ConnectionNumber(dpy), F_SETFD, 1) == -1)
  1644. X    {
  1645. X    fprintf(stderr, "twm: child cannot disinherit TCP fd\n");
  1646. X    exit(1);
  1647. X    }
  1648. X
  1649. X    Root = RootWindow(dpy, DefaultScreen(dpy));
  1650. X
  1651. X    XSetErrorHandler(Other);
  1652. X    XSelectInput(dpy, Root,
  1653. X    SubstructureRedirectMask |
  1654. X    ButtonPressMask | ButtonReleaseMask |
  1655. X    ExposureMask | ButtonMotionMask);
  1656. X    XSync(dpy, 0);
  1657. X
  1658. X    XSetErrorHandler(Error);
  1659. X    XSetInputFocus(dpy, Root, RevertToPointerRoot, CurrentTime);
  1660. X
  1661. X    TwmContext = XUniqueContext();
  1662. X    MenuContext = XUniqueContext();
  1663. X
  1664. X    /* define cursors */
  1665. X
  1666. X    ArrowCursor = XCreateFontCursor(dpy, XC_top_left_arrow);
  1667. X    MoveCursor = XCreateFontCursor(dpy, XC_fleur);
  1668. X    RightArrowCursor = XCreateFontCursor(dpy, XC_sb_right_arrow);
  1669. X    ButtonCursor = XCreateFontCursor(dpy, XC_center_ptr);
  1670. X    ClockCursor = XCreateFontCursor(dpy, XC_watch);
  1671. X
  1672. X    XGrabServer(dpy);
  1673. X    XSync(dpy, 0);
  1674. X    XQueryTree(dpy, Root, &root, &parent, &children, &nchildren);
  1675. X
  1676. X    ParseTwmrc(NULL);
  1677. X    FirstTime = FALSE;
  1678. X    CreateGCs();
  1679. X
  1680. X    for (i = 0; i < nchildren; i++)
  1681. X    {
  1682. X    if (MappedNotOverride(children[i]))
  1683. X    {
  1684. X        AddWindow(children[i]);
  1685. X    }
  1686. X    }
  1687. X
  1688. X    /* contruct the version string */
  1689. X    sprintf(Version, "%s", &Revision[1]);
  1690. X    Version[strlen(Version) - 1] = '\0';
  1691. X    sscanf(&Date[7], "%d/%d/%d", &y, &m, &d);
  1692. X    sprintf(Version, "%s  Date: %d/%d/%d %s", Version, m, d, y, &Date[16]);
  1693. X    Version[strlen(Version) - 2] = '\0';
  1694. X
  1695. X    VersionWindow = XCreateSimpleWindow(dpy, Root,
  1696. X    0, 0,
  1697. X    twm_width + XTextWidth(VersionFont, Version, strlen(Version)) + 20,
  1698. X    VersionFontHeight + 4,
  1699. X    BW,
  1700. X    Foreground, Background);
  1701. X
  1702. X    valuemask = CWBackPixmap;
  1703. X    attributes.background_pixmap = MakePixmap(VersionWindow, TitleNormalGC,
  1704. X    twm_bits, twm_width, twm_height);
  1705. X
  1706. X    XCreateWindow(dpy, VersionWindow,
  1707. X    4, 1,
  1708. X    twm_width, twm_height,
  1709. X    0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy, 0),
  1710. X    valuemask, &attributes);
  1711. X
  1712. X    XSelectInput(dpy, VersionWindow, ExposureMask);
  1713. X    XMapSubwindows(dpy, VersionWindow);
  1714. X    XMapWindow(dpy, VersionWindow);
  1715. X
  1716. X    SizeWindow = XCreateSimpleWindow(dpy, Root,
  1717. X    0, 0,
  1718. X    100,
  1719. X    SizeFontHeight + 4,
  1720. X    BW,
  1721. X    Foreground, Background);
  1722. X
  1723. X
  1724. X    XUngrabServer(dpy);
  1725. X
  1726. X    HandleEvents();
  1727. X}
  1728. X
  1729. X/***********************************************************************
  1730. X *
  1731. X *  Procedure:
  1732. X *    Done - cleanup and exit twm
  1733. X *
  1734. X *  Returned Value:
  1735. X *    none
  1736. X *
  1737. X *  Inputs:
  1738. X *    none
  1739. X *
  1740. X *  Outputs:
  1741. X *    none
  1742. X *
  1743. X *  Special Considerations:
  1744. X *    none
  1745. X *
  1746. X ***********************************************************************
  1747. X */
  1748. X
  1749. Xvoid
  1750. XDone()
  1751. X{
  1752. X    TwmWindow *tmp;            /* temp twm window structure */
  1753. X    unsigned x, y;
  1754. X    XWindowChanges xwc;        /* change window structure */
  1755. X    unsigned int xwcm;        /* change window mask */
  1756. X
  1757. X    /* put a border back around all windows */
  1758. X
  1759. X    for (tmp = TwmRoot.next; tmp != NULL; tmp = tmp->next)
  1760. X    {
  1761. X    XGetGeometry(dpy, tmp->w, &JunkRoot, &x, &y, &JunkWidth, &JunkHeight,
  1762. X        &JunkBW, &JunkDepth);
  1763. X
  1764. X    xwcm = CWX | CWY | CWBorderWidth;
  1765. X
  1766. X    xwc.x = x - (2 * BorderWidth);
  1767. X    xwc.y = y - (2 * BorderWidth);
  1768. X    xwc.border_width = BorderWidth;
  1769. X
  1770. X    XConfigureWindow(dpy, tmp->w, xwcm, &xwc);
  1771. X    }
  1772. X
  1773. X    XSetInputFocus(dpy, Root, RevertToPointerRoot, CurrentTime);
  1774. X    XCloseDisplay(dpy);
  1775. X    exit(0);
  1776. X}
  1777. X
  1778. X/***********************************************************************
  1779. X *
  1780. X *  Procedure:
  1781. X *    Error - X error handler.  Print the error and exit.
  1782. X *
  1783. X *  Inputs:
  1784. X *    dpy    - the connection to the X server
  1785. X *    event    - the error event structure
  1786. X *
  1787. X ***********************************************************************
  1788. X */
  1789. X
  1790. Xvoid
  1791. XError(dpy, event)
  1792. XDisplay *dpy;
  1793. XXErrorEvent *event;
  1794. X{
  1795. X    char buffer[BUFSIZ];
  1796. X
  1797. X    XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
  1798. X    (void) fprintf(stderr, "X Error: %s\n", buffer);
  1799. X    (void) fprintf(stderr, "  Request Major code: %d\n", event->request_code);
  1800. X    (void) fprintf(stderr, "  Request Minor code: %d\n", event->minor_code);
  1801. X    (void) fprintf(stderr, "  ResourceId 0x%x\n", event->resourceid);
  1802. X    (void) fprintf(stderr, "  Error Serial #%d\n", event->serial);
  1803. X    (void) fprintf(stderr, "  Current Serial #%d\n", dpy->request);
  1804. X
  1805. X    Done();
  1806. X}
  1807. X
  1808. X/***********************************************************************
  1809. X *
  1810. X *  Procedure:
  1811. X *    Other - error handler called if something else has set 
  1812. X *        the attributes on the root window.  Typically
  1813. X *        another window manager.
  1814. X *
  1815. X ***********************************************************************
  1816. X */
  1817. X
  1818. Xvoid
  1819. XOther(dpy, event)
  1820. XDisplay *dpy;
  1821. XXErrorEvent *event;
  1822. X{
  1823. X    fprintf(stderr, "twm: Are you running another window manager?\n");
  1824. X    exit(1);
  1825. X}
  1826. SHAR_EOF
  1827. if test 11469 -ne "`wc -c < twm.c`"
  1828. then
  1829.     echo shar: error transmitting "twm.c" '(should have been 11469 characters)'
  1830. fi
  1831. fi
  1832. if test -f 'parse.c'
  1833. then
  1834.     echo shar: will not over-write existing file "parse.c"
  1835. else
  1836. echo extracting "parse.c"
  1837. sed 's/^X//' >parse.c <<'SHAR_EOF'
  1838. X/*****************************************************************************/
  1839. X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  1840. X/**                          Salt Lake City, Utah                           **/
  1841. X/**                                                                         **/
  1842. X/**                           All Rights Reserved                           **/
  1843. X/**                                                                         **/
  1844. X/**    Permission to use, copy, modify, and distribute this software and    **/
  1845. X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  1846. X/**    granted, provided that the above copyright notice appear  in  all    **/
  1847. X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
  1848. X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
  1849. X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  1850. X/**    city pertaining to distribution  of the software without  specif-    **/
  1851. X/**    ic, written prior permission.                                        **/
  1852. X/**                                                                         **/
  1853. X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  1854. X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  1855. X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  1856. X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  1857. X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  1858. X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  1859. X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  1860. X/**    FORMANCE OF THIS SOFTWARE.                                           **/
  1861. X/*****************************************************************************/
  1862. X
  1863. X/***********************************************************************
  1864. X *
  1865. X * $Header: parse.c,v 1.13 88/04/15 07:09:29 tlastran Exp $
  1866. X *
  1867. X * parse the .twmrc file
  1868. X *
  1869. X * 17-Nov-87 Thomas E. LaStrange        File created
  1870. X *
  1871. X ***********************************************************************/
  1872. X
  1873. X#ifndef lint
  1874. Xstatic char RCSinfo[]=
  1875. X"$Header: parse.c,v 1.13 88/04/15 07:09:29 tlastran Exp $";
  1876. X#endif
  1877. X
  1878. X#include <stdio.h>
  1879. X#include "twm.h"
  1880. X#include "menus.h"
  1881. X#include "util.h"
  1882. X
  1883. X#define BUF_LEN 300
  1884. X
  1885. Xstatic FILE *twmrc;
  1886. Xstatic int ptr = 0;
  1887. Xstatic int len = 0;
  1888. Xstatic char buff[BUF_LEN+1];
  1889. Xextern int yylineno;
  1890. X
  1891. X/***********************************************************************
  1892. X *
  1893. X *  Procedure:
  1894. X *    ParseTwmrc - parse the .twmrc file
  1895. X *
  1896. X *  Inputs:
  1897. X *    filename  - the filename to parse.  A NULL indicates $HOME/.twmrc
  1898. X *
  1899. X ***********************************************************************
  1900. X */
  1901. X
  1902. Xvoid
  1903. XParseTwmrc(filename)
  1904. Xchar *filename;
  1905. X{
  1906. X    char *home;
  1907. X    char init_file[200];
  1908. X
  1909. X    InitMenus();
  1910. X    InitButtons();
  1911. X
  1912. X    if (filename == NULL)
  1913. X    {
  1914. X    home = (char *)getenv("HOME");
  1915. X    strcpy(init_file, home);
  1916. X    strcat(init_file, "/.twmrc");
  1917. X    }
  1918. X    else
  1919. X    strcpy(init_file, filename);
  1920. X
  1921. X    if ((twmrc = fopen(init_file, "r")) == NULL)
  1922. X    {
  1923. X    fprintf(stderr, "twm: couldn't open \"%s\"\n", init_file);
  1924. X        return;
  1925. X    }
  1926. X
  1927. X    ptr = 0;
  1928. X    len = 0;
  1929. X    yylineno = 0;
  1930. X    ParseError = FALSE;
  1931. X
  1932. X    yyparse();
  1933. X
  1934. X    fclose(twmrc);
  1935. X
  1936. X    if (ParseError)
  1937. X    {
  1938. X    fprintf(stderr, "twm: errors found in \"%s\", twm aborting\n",
  1939. X        init_file);
  1940. X    Done();
  1941. X    }
  1942. X}
  1943. X
  1944. X/***********************************************************************
  1945. X *
  1946. X *  Procedure:
  1947. X *    TwmInput - redefinition of the lex input routine
  1948. X *
  1949. X *  Returned Value:
  1950. X *    the next input character
  1951. X *
  1952. X ***********************************************************************
  1953. X */
  1954. X
  1955. Xchar
  1956. XTwmInput()
  1957. X{
  1958. X    while (ptr == len)
  1959. X    {
  1960. X    if (fgets(buff, BUF_LEN, twmrc) == NULL)
  1961. X        return NULL;
  1962. X
  1963. X    yylineno++;
  1964. X
  1965. X    ptr = 0;
  1966. X    len = strlen(buff);
  1967. X    }
  1968. X    return (buff[ptr++]);
  1969. X}
  1970. X
  1971. X/***********************************************************************
  1972. X *
  1973. X *  Procedure:
  1974. X *    TwmUnput - redefinition of the lex unput routine
  1975. X *
  1976. X *  Inputs:
  1977. X *    c    - the character to push back onto the input stream
  1978. X *
  1979. X ***********************************************************************
  1980. X */
  1981. X
  1982. Xvoid
  1983. XTwmUnput(c)
  1984. X{
  1985. X    buff[--ptr] = c;
  1986. X}
  1987. X
  1988. X/***********************************************************************
  1989. X *
  1990. X *  Procedure:
  1991. X *    TwmOutput - redefinition of the lex output routine
  1992. X *
  1993. X *  Inputs:
  1994. X *    c    - the character to print
  1995. X *
  1996. X ***********************************************************************
  1997. X */
  1998. X
  1999. Xvoid
  2000. XTwmOutput(c)
  2001. X{
  2002. X    putchar(c);
  2003. X}
  2004. SHAR_EOF
  2005. if test 4582 -ne "`wc -c < parse.c`"
  2006. then
  2007.     echo shar: error transmitting "parse.c" '(should have been 4582 characters)'
  2008. fi
  2009. fi
  2010. # end of shell archive
  2011. exit 0
  2012.  
  2013.